package com.xie.o2o.service;

import com.xie.o2o.dto.ShopExecution;
import com.xie.o2o.entity.Area;
import com.xie.o2o.entity.PersonInfo;
import com.xie.o2o.entity.Shop;
import com.xie.o2o.entity.ShopCategory;
import com.xie.o2o.enums.ShopStateEnum;
import org.apache.http.entity.ContentType;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.mock.web.MockMultipartFile;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Date;


/**
 * @create: xie
 */
@RunWith(SpringRunner.class)
@SpringBootTest
public class ShopServiceImpl{
    @Autowired
    ShopService shopService;
    @Test
    public void testGetShopList(){
        Shop shop=new Shop();
        ShopCategory shopCategory = new ShopCategory();
        shopCategory.setShopCategoryId(2L);
        shop.setShopCategory(shopCategory);
        ShopExecution shopList = shopService.getShopList(shop, 2, 1);
        System.out.println(shopList.getShopList().size());
    }

    @Test
    @Ignore
    public void testmodifyShop() throws IOException {
        Shop shop=new Shop();
        PersonInfo personInfo = new PersonInfo();
        Area area = new Area();
        ShopCategory shopCategory = new ShopCategory();
        personInfo.setUserId(1L);
        area.setAreaId(3);
        shop.setShopId(54L);
        shopCategory.setShopCategoryId(4L);
        shop.setArea(area);
        shop.setOwner(personInfo);
        shop.setShopCategory(shopCategory);
        shop.setShopName("咖啡店");
        shop.setShopDesc("香浓咖啡");
        shop.setShopAddr("东街");
        shop.setPhone("15646494");
        shop.setPriority(2);
        shop.setEnableStatus(1);
        shop.setAdvice("审核中");
        File file = new File("C:/2.jpg");
        FileInputStream fileInputStream = new FileInputStream(file);
        MultipartFile multipartFile = new MockMultipartFile("copy"+file.getName(),file.getName(), ContentType.APPLICATION_OCTET_STREAM.toString(),fileInputStream);
        shopService.modifyShop(shop,multipartFile);
    }

    @Test
    @Ignore
    public void test(){
        Shop shop = new Shop();
        PersonInfo owner = new PersonInfo();
        Area area = new Area();
        ShopCategory shopCategory = new ShopCategory();
        owner.setUserId(1L);
        area.setAreaId(2);
        shopCategory.setShopCategoryId(1L);
        shop.setOwner(owner);
        shop.setArea(area);
        shop.setShopCategory(shopCategory);
        shop.setShopName("测试的店铺3");
        shop.setShopDesc("test3");
        shop.setShopAddr("test3");
        shop.setPriority(2);
        shop.setPhone("test3");
        shop.setCreateTime(new Date());
        shop.setEnableStatus(ShopStateEnum.CHECK.getState());
        shop.setAdvice("审核中");

        File shopImg = new File("C:/2.jpg");
    }
}
